﻿//***********************************************************************
// * Module:   MsjZaAqjsffgcsjfaHandler
// * 作者:  曹荣芝
// * Modified: 2013-05-29
// * Purpose: Definition of the Class MsjZaAqjsffgcsjfaHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.JWBST.JWBSTBLL;
namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// MsjZaAqjsffgcsjfaHandler 的摘要说明
    /// </summary>
    public class MsjZaAqjsffgcsjfaHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {

        #region 添加记录
        /// <summary>
        /// 添加记录
        /// </summary>
        protected void AddRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {

                MsjZaAqjsffgcsjfa mMsjZaAqjsffgcsjfa = new MsjZaAqjsffgcsjfa();
                mMsjZaAqjsffgcsjfa.Gcid = Guid.NewGuid().ToString(); //主键
                mMsjZaAqjsffgcsjfa.Dwmc = context.Request.Form["texDwmc"]; //工程名称
                mMsjZaAqjsffgcsjfa.Dz = context.Request.Form["texDz"]; //地址
                mMsjZaAqjsffgcsjfa.Fxdj = context.Request.Form["texFxdj"]; //风险等级
                mMsjZaAqjsffgcsjfa.Ysje = Convert.ToDouble(context.Request.Form["texYsje"]); //预算金额（万元）
                mMsjZaAqjsffgcsjfa.JsdwMc = context.Request.Form["texJsdwMc"]; //建设单位_名称
                mMsjZaAqjsffgcsjfa.JsdwXmfzr = context.Request.Form["texJsdwXmfzr"]; //建设单位_项目负责人
                mMsjZaAqjsffgcsjfa.JsdwDz = context.Request.Form["texJsdwDz"]; //建设单位_地址
                mMsjZaAqjsffgcsjfa.JsdwLxdh = context.Request.Form["texJsdwLxdh"]; //建设单位_联系电话
                mMsjZaAqjsffgcsjfa.JsdwShsj = context.Request.Form["texJsdwShsj"]; //建设单位_审核时间
                mMsjZaAqjsffgcsjfa.JsdwShyj = context.Request.Form["texJsdwShyj"]; //建设单位_审核意见
                mMsjZaAqjsffgcsjfa.SgdwMc = context.Request.Form["texSgdwMc"]; //施工单位_名称
                mMsjZaAqjsffgcsjfa.SgdwXmfzr = context.Request.Form["texSgdwXmfzr"]; //施工单位_项目负责人
                mMsjZaAqjsffgcsjfa.SgdwDz = context.Request.Form["texSgdwDz"]; //施工单位_地址
                mMsjZaAqjsffgcsjfa.SgdwLxdh = context.Request.Form["texSgdwLxdh"]; //施工单位_联系电话
                mMsjZaAqjsffgcsjfa.GajgSpyj = context.Request.Form["texGajgSpyj"]; //公安机关_审批意见
                mMsjZaAqjsffgcsjfa.GajgShsj = context.Request.Form["texGajgShsj"]; //公安机关_审核时间
                mMsjZaAqjsffgcsjfa.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                mMsjZaAqjsffgcsjfa.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                mMsjZaAqjsffgcsjfa.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                mMsjZaAqjsffgcsjfa.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                mMsjZaAqjsffgcsjfa.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                mMsjZaAqjsffgcsjfa.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                mMsjZaAqjsffgcsjfa.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                mMsjZaAqjsffgcsjfa.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）

                mResultModel = MsjZaAqjsffgcsjfaBLL.Insert(mMsjZaAqjsffgcsjfa, context.Session["UserID"], true); //新建操作
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 删除记录
        /// <summary>
        /// 删除记录
        /// </summary>
        protected void DeleteRecord()
        {

            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            string paramKey = context.Request.Params["id"];
            try
            {
                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                MsjZaAqjsffgcsjfa mMsjZaAqjsffgcsjfa = new MsjZaAqjsffgcsjfa();
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mResultModel = MsjZaAqjsffgcsjfaBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); ; //序列化后返回
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, ""); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }

        }
        #endregion

        #region 修改记录
        /// <summary>
        /// 修改记录
        /// </summary>
        protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            MsjZaAqjsffgcsjfa mMsjZaAqjsffgcsjfa = new MsjZaAqjsffgcsjfa();

            string paramKey = context.Request.Params["id"];
            try
            {

                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                mMsjZaAqjsffgcsjfa = MsjZaAqjsffgcsjfaBLL.Load(paramKey); //根据键值获取实体信息
                if (mMsjZaAqjsffgcsjfa != null)
                {
                    mMsjZaAqjsffgcsjfa.Dwmc = context.Request.Form["texDwmc"]; //工程名称
                    mMsjZaAqjsffgcsjfa.Dz = context.Request.Form["texDz"]; //地址
                    mMsjZaAqjsffgcsjfa.Fxdj = context.Request.Form["texFxdj"]; //风险等级
                    mMsjZaAqjsffgcsjfa.Ysje = Convert.ToDouble(context.Request.Form["texYsje"]); //预算金额（万元）
                    mMsjZaAqjsffgcsjfa.JsdwMc = context.Request.Form["texJsdwMc"]; //建设单位_名称
                    mMsjZaAqjsffgcsjfa.JsdwXmfzr = context.Request.Form["texJsdwXmfzr"]; //建设单位_项目负责人
                    mMsjZaAqjsffgcsjfa.JsdwDz = context.Request.Form["texJsdwDz"]; //建设单位_地址
                    mMsjZaAqjsffgcsjfa.JsdwLxdh = context.Request.Form["texJsdwLxdh"]; //建设单位_联系电话
                    mMsjZaAqjsffgcsjfa.JsdwShsj = context.Request.Form["texJsdwShsj"]; //建设单位_审核时间
                    mMsjZaAqjsffgcsjfa.JsdwShyj = context.Request.Form["texJsdwShyj"]; //建设单位_审核意见
                    mMsjZaAqjsffgcsjfa.SgdwMc = context.Request.Form["texSgdwMc"]; //施工单位_名称
                    mMsjZaAqjsffgcsjfa.SgdwXmfzr = context.Request.Form["texSgdwXmfzr"]; //施工单位_项目负责人
                    mMsjZaAqjsffgcsjfa.SgdwDz = context.Request.Form["texSgdwDz"]; //施工单位_地址
                    mMsjZaAqjsffgcsjfa.SgdwLxdh = context.Request.Form["texSgdwLxdh"]; //施工单位_联系电话
                    mMsjZaAqjsffgcsjfa.GajgSpyj = context.Request.Form["texGajgSpyj"]; //公安机关_审批意见
                    mMsjZaAqjsffgcsjfa.GajgShsj = context.Request.Form["texGajgShsj"]; //公安机关_审核时间
                    mMsjZaAqjsffgcsjfa.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                    mMsjZaAqjsffgcsjfa.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                    mMsjZaAqjsffgcsjfa.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                    mMsjZaAqjsffgcsjfa.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                    mMsjZaAqjsffgcsjfa.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                    mMsjZaAqjsffgcsjfa.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                    mMsjZaAqjsffgcsjfa.Enabled = Enabled.TRUE; //是否有效（1有效，0无效）
                    mMsjZaAqjsffgcsjfa.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）

                    mResultModel = MsjZaAqjsffgcsjfaBLL.Update(mMsjZaAqjsffgcsjfa, context.Session["UserID"], true); //新建操作
                }
                else
                {
                    mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                    mResultModel.ISSucceed = false;

                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 获取实体记录
        /// <summary>
        /// 获取实体记录
        /// </summary>
        protected void GetModel()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            string paramKey = context.Request.Params["id"];
            string json = "";
            try
            {
                MsjZaAqjsffgcsjfa mMsjZaAqjsffgcsjfa = new MsjZaAqjsffgcsjfa(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mMsjZaAqjsffgcsjfa = MsjZaAqjsffgcsjfaBLL.Load(paramKey); //根据键值获取管理员
                    if (mMsjZaAqjsffgcsjfa != null)
                    {
                        json = JsonConvert.SerializeObject(mMsjZaAqjsffgcsjfa);
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            context.Response.Write(json);
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取数据记录
        /// </summary>
        protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
                return;
            DataTable dtMsjZaAqjsffgcsjfa = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            QueryByPage Q = new QueryByPage();
            QueryInfo qInfo = new QueryInfo();
            dtMsjZaAqjsffgcsjfa = Q.GetRecordByPage("*", "", "", intPageSize, intPageIndex, MsjZaAqjsffgcsjfaConst.TableName, MsjZaAqjsffgcsjfaConst.FieldKey, "").Tables[0];
            if (dtMsjZaAqjsffgcsjfa != null && dtMsjZaAqjsffgcsjfa.Rows.Count > 0)
            {
                for (int i = 0; i < dtMsjZaAqjsffgcsjfa.Columns.Count; i++)
                {
                    hm = new HearderMessage();
                    hm.name = dtMsjZaAqjsffgcsjfa.Columns[i].Caption;
                    list.Add(hm);
                }
                tm.Header = list;
                tm.data = dtMsjZaAqjsffgcsjfa;
                tm.totalCount = Convert.ToString((int)Q.RowCount);
            }
            string json = JsonConvert.SerializeObject(tm);
            context.Response.Write(json);
        }
        #endregion

    }
}


